package tech.xs.sys.service.impl;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.stereotype.Service;
import tech.xs.common.framework.service.CrudServiceImpl;
import tech.xs.sys.dao.SysRoleDao;
import tech.xs.sys.dao.SysUserRoleDao;
import tech.xs.sys.domain.entity.SysRole;
import tech.xs.sys.domain.entity.SysUserRole;
import tech.xs.sys.service.SysUserRoleService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@Service
public class SysUserRoleServiceImpl extends CrudServiceImpl<SysUserRoleDao, SysUserRole> implements SysUserRoleService {

    @Resource
    private SysUserRoleDao sysUserRoleDao;
    @Resource
    private SysRoleDao sysRoleDao;

    @Override
    public List<SysRole> getRolesByUserName(String userName) {
        return sysRoleDao.selectJoinList(SysRole.class, new MPJLambdaWrapper<SysRole>().selectAll(SysRole.class)
                .leftJoin(SysUserRole.class, SysUserRole::getRoleCode, SysRole::getCode)
                .eq(SysUserRole::getUserName, userName)
                .orderByAsc(SysRole::getCode)
        );
    }

    @Override
    public Set<String> getRoleCodesByUserName(String userName) {
        return sysUserRoleDao.selectRoleCodesByUserName(userName);
    }

}
